package com.whu.tcx01.hd.calNewRoad;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class RoadMapper extends Mapper<LongWritable, Text, Text, RoadBean> {
    private Text outK = new Text();
    private RoadBean outV = new RoadBean();

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {

        // 1 获取一行
        String s = value.toString();
        System.out.println(s);

        // 2 切割
        String[] split = s.split("\t");

        // 3 封装
        outK.set(split[1] + "\t" + split[2]);
        outV.setRoadid(Long.parseLong(split[0]));
        outV.setStart(Long.parseLong(split[1]));
        outV.setStop(Long.parseLong(split[2]));
        outV.setDirection(Integer.parseInt(split[3]));
        outV.setDistance(Double.parseDouble(split[4]));
        outV.setPathclass(Integer.parseInt(split[5]));
        outV.setSpeed(Double.parseDouble(split[6]));

        // 4 写出
        context.write(outK, outV);
    }
}
